package com.yanqu.road.server.cmd.activity.relation;

import com.yanqu.road.entity.rank.UnionActivityRank;
import com.yanqu.road.logic.pb.CrossRankPb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.pb.rank.UnionActivityRankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.relation.CrossRelationRankMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_RELATION_ACTIVITY_UNION_RANK_CHANGE, desc = "跨服小当家类型商会排行数据变化")
public class CrossRelationUnionRankChangeCmd extends CrossCommand {

    private int activityId;

    private boolean isAll;

    private boolean isUnionDel;//是否商会解散

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossActivityUnionRankChangeReqMsg reqMsg = CrossActivityProto.CrossActivityUnionRankChangeReqMsg.parseFrom(packet.getBytes());
        isAll = reqMsg.getIsAll();
        activityId = reqMsg.getActivityId();
        isUnionDel = reqMsg.getIsUnionDel();
        for(UnionActivityRankProto.UnionActivityRankTempMsg temMsg : reqMsg.getDataListList()) {
            UnionActivityRank unionRank = CrossRankPb.parseUnionActivityRank(activityId, temMsg);
            CrossRelationRankMgr.changeRelationUnionRank(activityId, unionRank,isUnionDel);
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        if(isAll){
            CrossActivityProto.CrossActivityRankChangeRespMsg.Builder respMsg = CrossActivityProto.CrossActivityRankChangeRespMsg.newBuilder();
            respMsg.setActivityId(activityId);
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_ACTIVITY_CHANGE_HAS_ALL_SYNC, respMsg);
            MessageHelper.sendPacket(serverId, 0, pbMsg);
        }
    }

    @Override
    public void sendData() {

    }
}
